package com.springboot.cms.footer.controller;

import com.springboot.cms.footer.domain.CmsFooter;
import com.springboot.cms.footer.service.ICmsFooterService;
import com.springboot.common.annotation.Log;
import com.springboot.common.core.controller.BaseController;
import com.springboot.common.core.domain.AjaxResult;
import com.springboot.common.core.page.TableDataInfo;
import com.springboot.common.enums.BusinessType;
import com.springboot.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 网站页脚Controller
 *
 * @author lhxz
 * @date 2024-07-06
 */
@RestController
@RequestMapping("/cms/footer")
public class CmsFooterController extends BaseController
{
    @Autowired
    private ICmsFooterService cmsFooterService;

    /**
     * 查询网站页脚列表
     */
//    @PreAuthorize("@ss.hasPermi('cms:footer:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsFooter cmsFooter)
    {
        startPage();
        List<CmsFooter> list = cmsFooterService.selectCmsFooterList(cmsFooter);
        return getDataTable(list);
    }

    /**
     * 导出网站页脚列表
     */
    @PreAuthorize("@ss.hasPermi('cms:footer:export')")
    @Log(title = "网站页脚", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsFooter cmsFooter)
    {
        List<CmsFooter> list = cmsFooterService.selectCmsFooterList(cmsFooter);
        ExcelUtil<CmsFooter> util = new ExcelUtil<CmsFooter>(CmsFooter.class);
        util.exportExcel(response, list, "网站页脚数据");
    }

    /**
     * 获取网站页脚详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:footer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(cmsFooterService.selectCmsFooterById(id));
    }

    /**
     * 新增网站页脚
     */
    @PreAuthorize("@ss.hasPermi('cms:footer:add')")
    @Log(title = "网站页脚", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsFooter cmsFooter)
    {
        return toAjax(cmsFooterService.insertCmsFooter(cmsFooter));
    }

    /**
     * 修改网站页脚
     */
    @PreAuthorize("@ss.hasPermi('cms:footer:edit')")
    @Log(title = "网站页脚", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsFooter cmsFooter)
    {
        return toAjax(cmsFooterService.updateCmsFooter(cmsFooter));
    }

    /**
     * 删除网站页脚
     */
    @PreAuthorize("@ss.hasPermi('cms:footer:remove')")
    @Log(title = "网站页脚", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(cmsFooterService.deleteCmsFooterByIds(ids));
    }
}
